package service

import (
	"gitee.com/sansaniot/ssiot-core/sdk/service"
	uuid "github.com/satori/go.uuid"
	"ssadmin/internal/admin/models"
	"ssadmin/internal/admin/models/command"
)

type SysLogo struct {
	service.Service
}

// Get 获取UserLogo对象
func (e *SysLogo) Get(d *command.SysLogoReq, model *models.SysLogo) error {
	e.Orm.Model(&models.SysLogo{}).First(&model, d)
	return nil
}

// Save 修改
func (e *SysLogo) Save(req *command.SysLogoReq) error {
	var data = models.SysLogo{}
	e.Orm.First(&data, "user_id = ? and systemid = ?", req.UserId, req.Systemid)
	req.Generate(&data)

	if len(data.Id) == 0 {
		data.Id = uuid.NewV4().String()
		e.Orm.Save(&data)
	} else {
		e.Orm.Save(&data)
	}

	req.Id = data.Id
	return nil
}
